﻿#region Header

// <file>
//     <copyright see="prj:///doc/copyright.txt"/>
//     <license see="prj:///doc/license.txt"/>
//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
//     <version>$Revision: 1965 $</version>
// </file>

#endregion Header

namespace ICSharpCode.TextEditor.Document
{
    using System.Collections.Generic;
    using System.IO;
    using System.Reflection;
    using System.Xml;

    public class ResourceSyntaxModeProvider : ISyntaxModeFileProvider
    {
        #region Fields

        List<SyntaxMode> syntaxModes = null;

        #endregion Fields

        #region Constructors

        public ResourceSyntaxModeProvider()
        {
            Assembly assembly = typeof(SyntaxMode).Assembly;
            Stream syntaxModeStream = assembly.GetManifestResourceStream("ICSharpCode.TextEditor.Resources.SyntaxModes.xml");
            if (syntaxModeStream != null) {
                syntaxModes = SyntaxMode.GetSyntaxModes(syntaxModeStream);
            } else {
                syntaxModes = new List<SyntaxMode>();
            }
        }

        #endregion Constructors

        #region Properties

        public ICollection<SyntaxMode> SyntaxModes
        {
            get {
                return syntaxModes;
            }
        }

        #endregion Properties

        #region Methods

        public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode)
        {
            Assembly assembly = typeof(SyntaxMode).Assembly;
            return new XmlTextReader(assembly.GetManifestResourceStream("ICSharpCode.TextEditor.Resources." + syntaxMode.FileName));
        }

        public void UpdateSyntaxModeList()
        {
            // resources don't change during runtime
        }

        #endregion Methods
    }
}